package com.hongding.sealcenter.helper;


import cn.hutool.extra.spring.SpringUtil;
import com.hongding.sealcenter.util.SpringUtils;
import com.hongding.sealcenter.vo.CACertificateVO;
import com.hongding.sealcenter.vo.PkcsVO;

/**
 * CA证书策略
 */
public interface CAHelper {
    String BASE_NAME = "Helper";
    /**
     * 获取证书
     * @param caCertificateVO 获取证书信息
     * @param password 证书密码
     * @return
     * @throws RuntimeException
     */
    static PkcsVO singleCertificate(CACertificateVO caCertificateVO, String password) throws RuntimeException {
        // 授权类型和客户端id
        String beanName = caCertificateVO.getCaType() + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new RuntimeException("授权类型不正确!");
        }
        CAHelper instance = SpringUtil.getBean(beanName);
        return instance.applyCertificate(caCertificateVO,password);
    }

    /**
     * 获取证书
     * @param caCertificateVO 获取证书信息
     * @param password 证书密码
     * @return
     * @throws RuntimeException
     */
    PkcsVO applyCertificate(CACertificateVO caCertificateVO,String password) throws RuntimeException;
}